package com.android.qjpmc.application_module.pop;

import com.android.qjpmc.R;
import com.android.qjpmc.application_module.home.model.StationDataModel;
import com.android.qjpmc.bean.ListCheckPopBean;
import com.android.qjpmc.bean.PointParameterBean;
import com.android.qjpmc.databinding.ItemPopDevicesBinding;
import com.android.qjpmc.databinding.ItemPopListBinding;
import com.android.qjpmc.databinding.PopListCheckBinding;
import com.android.qjpmc.widget.base.BasePopupWindow;
import com.android.qjpmc.widget.databindingadapter.BaseBindingItemPresenter;
import com.android.qjpmc.widget.databindingadapter.BaseDataBindingDecorator;
import com.android.qjpmc.widget.databindingadapter.SingleTypeBindingAdapter;
import com.android.qjpmc.widget.utils.UIUtils;

import java.util.List;
import java.util.Map;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

public class ListCheckPopupWindow extends BasePopupWindow<PopListCheckBinding> implements BaseBindingItemPresenter<ListCheckPopBean> {

    private SingleTypeBindingAdapter adapter;
    private List<ListCheckPopBean> popListData;
    private ListCheckPopupWindowListener listCheckPopupWindowListener;
    StationDataModel stationDataModel = new StationDataModel();

    public ListCheckPopupWindow(FragmentActivity activity) {
        super(activity);
    }

    @Override
    public int getLayoutId() {
        return R.layout.pop_list_check;
    }

    @Override
    public void initView() {
        initRecycler(popListData);
    }


    private void initRecycler(List<ListCheckPopBean> devicesList) {
        initCategoryRecyclerView(devicesList, 0);
    }

    private void initCategoryRecyclerView(List<ListCheckPopBean> popListData, int categorySelectPosition) {
        this.popListData = popListData;
       // popListData.get(categorySelectPosition).isOpen = true;
        adapter = new SingleTypeBindingAdapter(UIUtils.getContext(), popListData, R.layout.item_pop_list);
        mBinding.recyclerView.setAdapter(adapter);
        adapter.setItemPresenter(this);
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(activitySoftReference.get()));
        adapter.setItemDecorator(new BaseDataBindingDecorator<ListCheckPopBean, ItemPopListBinding>() {
            @Override
            public void decorator(ItemPopListBinding binding, int position, int viewType, ListCheckPopBean data) {
                if (data.isOpen) {
                    binding.llContent.setBackgroundResource(R.color.white);
                } else {
                    binding.llContent.setBackgroundResource(R.color.gray_f8);
                }
            }
        });

    }

    @Override
    public void initData() {
    }

    @Override
    public void initEvent() {

    }


    @Override
    public void onItemClick(int itemPosition, ListCheckPopBean itemData) {
        if (itemData.isOpen) return;
        List<ListCheckPopBean> listData = adapter.getListData();
        for (ListCheckPopBean listDatum : listData) {
            listDatum.isOpen = false;
        }
        itemData.isOpen = true;
        adapter.notifyDataSetChanged();
        dismiss();
        if (listCheckPopupWindowListener != null) {
            listCheckPopupWindowListener.onPopChooseResult(popListData);
        }
    }


    public void initListData(List<ListCheckPopBean> popListData) {
        this.popListData = popListData;
    }


    public void setListCheckPopupWindowListener(ListCheckPopupWindowListener courseSearchPopFilterListener) {
        this.listCheckPopupWindowListener = courseSearchPopFilterListener;
    }

    public interface ListCheckPopupWindowListener {

        void onPopChooseResult(List<ListCheckPopBean> popListData);
    }


}


